﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using PiscoSourDominio;
using PiscoSourSOAPRestServices.Persistencia;
using Dapper;

namespace PiscoSourRESTServices.Persistencia
{
    public class ClienteDAO
    {

        public Cliente ObtenerClientes(int codigo)
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                const string sqlQuery = "select * from prs_cliente where intcliente=@intcliente";
                var cliente = sqlConnection.Query<Cliente>(sqlQuery, new { intcliente = codigo }).SingleOrDefault<Cliente>();

                sqlConnection.Close();

                return cliente;
            }
        }

        public IEnumerable<Cliente> ListarClientes()
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                var sqlQuery = string.Format(@"Select * from prs_cliente");
                var result = sqlConnection.Query<Cliente>(sqlQuery);
                sqlConnection.Close();
                return result;
            }
        }
    }
}